package sky.wicket;

import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.RadioChoice;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.springframework.beans.factory.annotation.Autowired;
import sky.service.CityService;
import sky.tro.TicketFinder;

import java.util.Arrays;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 * User: Gauss
 * Date: 27.08.13
 * Time: 12:14
 * To change this template use File | Settings | File Templates.
 */
public class FindFlight extends BasePage {

    private TicketFinder ticketFinder = new TicketFinder();

    public FindFlight() {
        ticketFinder.setTicketType("Econom");
        Form<TicketFinder> flightCriteria = new Form<TicketFinder>("flightCriteria", new CompoundPropertyModel<TicketFinder>(ticketFinder)) {

            @Override
            protected void onSubmit() {
                setResponsePage(new BookingFlight(ticketFinder));
            }

            @Override
            protected void onError() {
            }
        };
        //departure
        /*final AutoCompleteTextField<String> field = new AutoCompleteTextField<String>("departureCity") {

            @Override
            protected Iterator<String> getChoices(String autocompleteString) {
                System.out.println("ajax");
                if (Strings.isEmpty(autocompleteString)) {
                    List<String> emptyList = Collections.emptyList();
                    return emptyList.iterator();
                }
                List<String> choices;
                choices = cityService.autocompleteList(autocompleteString);
                return choices.iterator();
            }
        };*/

        /*field.add(new AjaxFormComponentUpdatingBehavior("onchange") {
            @Override
            protected void onUpdate(AjaxRequestTarget ajaxRequestTarget) {
                if (ajaxRequestTarget != null) {
                    ajaxRequestTarget.add(field);
                }
            }
        });*/
        flightCriteria.add(new TextField<String>("departureCity"));
        flightCriteria.add(new TextField<Date>("departureFromDate"));
        flightCriteria.add(new TextField<Date>("departureToDate"));
        //destination
        flightCriteria.add(new TextField<String>("destinationCity"));
        flightCriteria.add(new TextField<Date>("destinationFromDate"));
        flightCriteria.add(new TextField<Date>("destinationToDate"));
        //ticket type
        flightCriteria.add(new RadioChoice<String>("ticketType", Arrays.asList(
                "Econom", "Bussiness", "FirstClass"
        )).setRequired(true));
        flightCriteria.add(new DropDownChoice<Integer>("ticketCount", Arrays.asList(
                1, 2, 3, 4, 5, 6
        )).setRequired(true));
        flightCriteria.add(new TextField<Integer>("priceFrom"));
        flightCriteria.add(new TextField<Integer>("priceTo"));
        add(flightCriteria);
        add(new FeedbackPanel("feedback"));
    }

}
